package inabit.expressioncompiler.compiler;

import inabit.compiler.compiler.LanguageCompiler;
import inabit.data.InabitMethod;
import inabit.data.expression.arithmetic.ArithmeticExpression;
import inabit.expressioncompiler.lexical.ExpressionLexicalAnalyzer;
import inabit.expressioncompiler.parser.ExpressionParser;

import java.util.HashMap;
import java.util.Map;
/**@author Rafael Rocha*/
public class ExpressionCompiler extends LanguageCompiler<ExpressionLexicalAnalyzer, ExpressionParser>{

	private ArithmeticExpression compiledExpression;
	private Map<String, InabitMethod> methodMap;
	
	public ExpressionCompiler() {
		super(new ExpressionLexicalAnalyzer(), new ExpressionParser());
		methodMap = new HashMap<String, InabitMethod>();
	}

	@Override
	protected void init(ExpressionLexicalAnalyzer lexer, ExpressionParser parser) {
		parser.setMethods(methodMap);
	}

	@Override
	protected void deinit(ExpressionLexicalAnalyzer lexer, ExpressionParser parser) {
		this.compiledExpression = parser.getCompiledExpression();
	}
	public void addMethod(InabitMethod method) {
		methodMap.put(method.getName(), method);
	}
	public void removeMethod(String methodName) {
		methodMap.remove(methodName);
	}
	public ArithmeticExpression getCompiledExpression() {
		return compiledExpression;
	}

}

